package com.example.parallaxlistview;

import android.content.Context;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.widget.ListView;

public class BounceListView extends ListView{

	private Context mConext;
	private int mMaxYOverscrollDistance;
	private int MAX_Y_OVERSCROLL_DISTANCE;
	
	public BounceListView(Context context){
		super(context);
	}
	
	public BounceListView(Context context, AttributeSet attrs){
		super(context, attrs);
	}
	
	public BounceListView(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		mConext = context;
		initBounceListView();
	}
	
	private void initBounceListView(){
		final DisplayMetrics metris  = mConext.getResources().getDisplayMetrics();
		final float density = metris.density;
		mMaxYOverscrollDistance = (int) (density * MAX_Y_OVERSCROLL_DISTANCE);
	}
	
	@Override
	protected boolean overScrollBy(int deltaX, int deltaY, int scrollX,
			int scrollY, int scrollRangeX, int scrollRangeY,
			int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) {
		//当ListView滑动超出范围是回调该方法，并且提供参数给你做一些处理
		return super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX,
				scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent);
	}
	
}
